// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space

import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.*;

public class Chart extends ApplicationFrame
{
		DefaultCategoryDataset defaultcategorydataset ;
		double days = 0 ; 			//0.9302,9.5238,1.18203,0.49504,12.1951 
		//public double Avg[ ] = new double[ ] { 64.5 , 10.5 , 42.3 , 30.3 , 8.2 } ;
		public double Avg[ ] = new double[ ] { 100.0, 100.0, 100.0, 100.0, 100.0 } ;
		public double Now[ ] = new double[ ] { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } ;
		public double Nvg[ ] = new double[ ] { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } ;
		//public double per[ ] = new double[ ] { 0.6 , 1.0 , 0.5 , 0.15 , 1.0 } ;
		public double per[ ] = new double[ ] { 0.9302, 9.5238, 1.18203, 0.49504, 12.1951 } ;
		public String Nam[ ] = new String[ ] { "五穀根莖類" , "蛋類" , "肉類" , "油脂類" , "水果類" } ;
        public Chart( String s )
        {
                super( s ) ;
                JPanel jpanel = createDemoPanel( ) ;
                jpanel.setPreferredSize( new Dimension( 1050 , 560 ) ) ;
                setContentPane( jpanel ) ;
                System.out.println( "xxx" ) ;                
        }
        void ModifyData( int FID , double Hot )
        {
        	Now[ FID ] = Now[ FID ] + Hot * per[ FID ] / 10 ;
        	defaultcategorydataset.setValue( Now[ FID ] , "當日攝取量" , Nam[ FID ] ) ;	
        	
        }
        void ModifyDataDay( )
        {
        	days++ ;
        	for( int i = 0 ; i < 5 ; i++ )
        	{
        		Nvg[ i ] = ( Nvg[ i ]*(days-1) + Now[ i ] ) / days ;
        		defaultcategorydataset.setValue( Nvg[ i ] , "每日平均攝取量" , Nam[ i ] ) ;	
        		Now[ i ] = 0 ;
        		defaultcategorydataset.setValue( Now[ i ] , "當日攝取量"   , Nam[ i ] ) ;	
        	}
        }
        void SetZero( )
        {
        	//days = 0 ;
        	for( int i = 0 ; i < 5 ; i++ )
        	{
        		Now[ i ] = 0 ;
        		defaultcategorydataset.setValue( Now[ i ] , "當日攝取量"   , Nam[ i ] ) ;	
        		//defaultcategorydataset.setValue( Nvg[ i ] , "每日平均攝取量" , Nam[ i ] ) ;	
        	}
        }
        private CategoryDataset createDataset()
        {
        	/*Meat Grain Oil Fruit Egg*/
            String s  = "當日攝取量" ;
            String s1 = "標準值" ;
            String s2 = "每日平均攝取量" ;
            
            //3-6, 350 碗   1575  * 0.6  645
            String s3 = "五穀根莖類" ;
            //1-2, 70  顆  105   * 1.0  105 
            String s4 = "蛋類" ;
            //4-5, 190 份  855   *  0.5 423
            String s5 = "肉類" ;
            //2-3, 810 匙  2025 * 0.15  303 
            String s6 = "油脂類" ;
            //1-2, 55  顆  82.5 * 1.0    82
            String s7 = "水果類" ;
            
            defaultcategorydataset = new DefaultCategoryDataset( ) ;
            defaultcategorydataset.addValue( Now[ 0 ] , s  , s3 ) ;
            defaultcategorydataset.addValue( Now[ 1 ] , s  , s4 ) ;
            defaultcategorydataset.addValue( Now[ 2 ] , s  , s5 ) ;
            defaultcategorydataset.addValue( Now[ 3 ] , s  , s6 ) ;
            defaultcategorydataset.addValue( Now[ 4 ] , s  , s7 ) ;
           
            defaultcategorydataset.addValue( Avg[ 0 ] , s1 , s3 ) ;
            defaultcategorydataset.addValue( Avg[ 1 ] , s1 , s4 ) ;
            defaultcategorydataset.addValue( Avg[ 2 ] , s1 , s5 ) ;
            defaultcategorydataset.addValue( Avg[ 3 ] , s1 , s6 ) ;
            defaultcategorydataset.addValue( Avg[ 4 ] , s1 , s7 ) ;
           
            defaultcategorydataset.addValue( Nvg[ 0 ] , s2 , s3 ) ;
            defaultcategorydataset.addValue( Nvg[ 1 ] , s2 , s4 ) ;
            defaultcategorydataset.addValue( Nvg[ 2 ] , s2 , s5 ) ;
            defaultcategorydataset.addValue( Nvg[ 3 ] , s2 , s6 ) ;
            defaultcategorydataset.addValue( Nvg[ 4 ] , s2 , s7 ) ;
            return defaultcategorydataset ;
        }

        private JFreeChart createChart( CategoryDataset categorydataset )
        {
        	days = 0 ;
            SpiderWebPlot spiderwebplot = new SpiderWebPlot( categorydataset ) ;
            spiderwebplot.setStartAngle( 90D ) ;
            spiderwebplot.setInteriorGap( 0.40000000000000002D ) ;
            spiderwebplot.setToolTipGenerator( new StandardCategoryToolTipGenerator( ) ) ;
            JFreeChart jfreechart   = new JFreeChart( "營養力圖" , TextTitle.DEFAULT_FONT , spiderwebplot , false ) ;
            LegendTitle legendtitle = new LegendTitle( spiderwebplot ) ;
            legendtitle.setPosition( RectangleEdge.BOTTOM ) ;
            jfreechart.addSubtitle( legendtitle ) ;
            return jfreechart ;
        }

        public JPanel createDemoPanel()
        {
            JFreeChart jfreechart = createChart(createDataset());
            return new ChartPanel(jfreechart);
        }
}
